// Copyright (c) 2009 Mike Haight, Andy Kipp
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.

#include "stdafx.h"

#pragma once

namespace HandBanana { namespace Resources
{
    /// <summary>
    /// 
    /// </summary>
    [XmlRoot(ElementName = "Texture")]
    public ref class Texture : public System::Xml::Serialization::IXmlSerializable
    {

    // Constructors
    public:

        /// <summary>
        /// Create a new instance of the Texture class
        /// <summary>
        Texture(String^ argName, int argWidth, int argHeight, int argFrameWidth, int argFrameHeight);

    // Constructors
    private:

        /// <summary>
        /// 
        /// <summary>
        Texture(void);

    // Destructor
    private:

        /// <summary>
        /// Cleans up outstanding references to allocated textures.
        /// </summary>
        ~Texture(void);

    // Public Properties
    public:

        /// <summary>
        /// Gets the pointer to the DirectX texture.
        /// </summary>
        property IntPtr NativeTexturePointer
        {
            IntPtr get(void);
        }

        /// <summary>
        /// Gets the name of the texture.
        /// </summary>
        property String^ Name
        {
            String^ get(void);
        }

        /// <summary>
        /// Gets the height of the texture, in pixels.
        /// </summary>
        property int Height
        {
            int get(void);
        }

        /// <summary>
        /// Gets the width of the texture, in pixels.
        /// </summary>
        property int Width
        {
            int get(void);
        }

        /// <summary>
        /// Gets the height of each frame of the texture.
        /// </summary>
        property int FrameHeight
        {
            int get(void);
        }

        /// <summary>
        /// Gets the width of each frame of the texture.
        /// </summary>
        property int FrameWidth
        {
            int get(void);
        }

    // Public Methods
    public:

        /// <summary>
        /// 
        /// </summary>
        void AddReference(void);

        /// <summary>
        /// 
        /// </summary>
        void Release(void);

        /// <summary>
        /// Gets a numbered frame from the texture.
        /// </summary>
        Frame GetFrame(int argFrameId);

    // IXmlSerializable Methods
    public:

        /// <summary>
        /// 
        /// </summary>
        virtual void WriteXml(XmlWriter^ writer);

        /// <summary>
        /// 
        /// </summary>
        virtual void ReadXml(XmlReader^ reader);

        /// <summary>
        /// 
        /// </summary>
        virtual XmlSchema^ GetSchema(void);

    // Private Fields
    private:
        // Static Logger for this Class
        static NLog::Logger^            smLogger = NLog::LogManager::GetCurrentClassLogger();

        IntPtr      mTexturePointer;

        String^     mName;
        int         mWidth;
        int         mHeight;
        int         mFrameWidth;
        int         mFrameHeight;

        int         mReferenceCount;

        int         mFramesPerRow;
        float       mFloatFrameWidth;
        float       mFloatFrameHeight;

    };
} }